package com.lc.afbx.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lc.afbx.BaseApplication;
import com.lc.afbx.R;
import com.lc.afbx.util.PrefrenceConfig;
import com.zcx.helper.util.UtilToast;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/5/19.
 */
public class BusinessInsuranceActivity extends BaseActivity implements View.OnClickListener {


    private Button btnXiaYiBu;
    private RelativeLayout rLayoutBack;
    private RelativeLayout rlayout;
    private TextView cityName;
    private LinearLayout lLayoutXinBao;
    private ImageView imgXinBao;
    private LinearLayout lLayoutXuBao;
    private ImageView imgXuBao;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shouye_jiaoqiangxian);

        initView();

        setListener();
    }

    private void setListener() {

        rLayoutBack.setOnClickListener(this);
        btnXiaYiBu.setOnClickListener(this);
        rlayout.setOnClickListener(this);
        lLayoutXinBao.setOnClickListener(this);
        lLayoutXuBao.setOnClickListener(this);


    }

    private void initView() {

        rLayoutBack = ((RelativeLayout) findViewById(R.id.back));
        btnXiaYiBu = ((Button) findViewById(R.id.shouye_btn_jiaoqiangxian_xiayibu));
        rlayout = ((RelativeLayout) findViewById(R.id.lLayout_area));
        cityName = ((TextView) findViewById(R.id.cityName));

        lLayoutXinBao = ((LinearLayout) findViewById(R.id.xinBao));
        imgXinBao = ((ImageView) findViewById(R.id.imgXinBao));
        lLayoutXuBao = ((LinearLayout) findViewById(R.id.xuBao));
        imgXuBao = ((ImageView) findViewById(R.id.imgXubao));

        //默认选新保
        imgXinBao.setImageResource(R.mipmap.szmrdz);
        imgXuBao.setImageResource(R.mipmap.lvquan);
        imgXinBao.setTag(true);
        imgXuBao.setTag(false);
    }

    @Override
    public void onClick(View view) {

        Intent intent = null;
        switch (view.getId()) {

            case R.id.back:
                finish();
                return;

            case R.id.xinBao:

                imgXinBao.setImageResource(R.mipmap.szmrdz);
                imgXuBao.setImageResource(R.mipmap.lvquan);
                imgXinBao.setTag(true);
                imgXuBao.setTag(false);
                return;

            case R.id.xuBao:
                imgXinBao.setImageResource(R.mipmap.lanquan);
                imgXuBao.setImageResource(R.mipmap.nv);
                imgXinBao.setTag(false);
                imgXuBao.setTag(true);
                return;

            case R.id.lLayout_area:
                intent = new Intent(context, ChoseAreaActivity.class);
                intent.putExtra(PrefrenceConfig.INTENT_TAG, "area");
                startActivityForResult(intent, 3);
                return;

            case R.id.shouye_btn_jiaoqiangxian_xiayibu:

                //判断  跳转登录
                if (BaseApplication.BasePreferences.readIsLogin() == false) {
                    intent = new Intent(this, LoginActivity.class);
                    startActivity(intent);
                    return;
                }
                if (cityName.getText().toString().isEmpty() || cityName.getText().toString() == null) {
                    UtilToast.show(context, "请选择城市地区");
                    return;
                }
                boolean flag = (boolean) imgXinBao.getTag();
                if (flag) {
                    intent = new Intent(this, BusinessInsuranceChooseCompanyActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putString("insurance_type", "1");
                    intent.putExtras(bundle);
                } else {
                    intent = new Intent(this, RenewalActivity.class);
                    intent.putExtra(PrefrenceConfig.INTENT_TAG, "BusinessInsuranceActivity");
                }

                break;

        }
        if (intent == null) {
            UtilToast.show(context, "intent 空了");
            return;
        }
        startActivity(intent);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

//        UtilLog.e("看看","这个方法走没走啊");
        switch (resultCode) {
            case 3:

                Bundle bundle = data.getExtras();

                ArrayList list = bundle.getParcelableArrayList("list");

                List<Map<String, String>> lists = (List<Map<String, String>>) list.get(0);

                BaseApplication.BasePreferences.saveCityID(lists.get(1).get("id"));

                cityName.setText(lists.get(1).get("title") + "\t" + lists.get(2).get("title"));


                break;
            default:
                break;
        }
    }

}
